﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace cjwygl
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button_cancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button_login_Click(object sender, EventArgs e)
        {
            using (DataBase db = new DataBase())
            {
                db.AddParameter("USERNAME", textBox_username.Text);
                db.AddParameter("PASSWORD", textBox_password.Text);
                DataTable dt = db.ExecuteDataTable("SELECT A.[ID],[USERNAME],[NICKNAME],[ROLE_NAME],"+
                    "[PERMISSIONS] FROM CJ_ADMIN A,CJ_ROLE B WHERE A.ROLE_ID=B.ID AND "+
                    "USERNAME=@USERNAME AND PASSWORD=@PASSWORD");
                if (dt.Rows.Count > 0)
                {
                    userinfo.nickname = dt.Rows[0][2].ToString();
                    userinfo.rolename = dt.Rows[0][3].ToString();
                    userinfo.username = dt.Rows[0][1].ToString();
                    userinfo.id = int.Parse(dt.Rows[0][0].ToString());
                    userinfo.permissions = dt.Rows[0][4].ToString();
                    this.Hide();
                    FrmControlPanel frmCtrlPanel = new FrmControlPanel();
                    frmCtrlPanel.Show();
                }
                else
                {
                    db.Dispose();
                    MessageBox.Show("用户名或密码不正确!");
                    return;
                }
            }
            
            
        }
    }
    public static class userinfo
    {
        public static string username;
        public static string nickname;
        public static string rolename;
        public static int id;
        public static string permissions;
        public static bool hasPermission(string permission)
        {
            if (permissions.IndexOf(permission) >= 0)
                return true;
            return false;
        }
    }
}
